package com.dkts.oil.router;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class RouteStrategyFactory {

    private final Map<String, RouteStrategy<?, ?>> strategyMap;

    @Autowired
    public RouteStrategyFactory(Map<String, RouteStrategy<?, ?>> strategyMap) {
        this.strategyMap = strategyMap;
    }

    @SuppressWarnings("unchecked")
    public <T, R> RouteStrategy<T, R> getStrategy(String key) {
        RouteStrategy<?, ?> strategy = strategyMap.get(key);
        if (strategy == null) {
            throw new IllegalArgumentException("未找到策略: " + key);
        }
        return (RouteStrategy<T, R>) strategy;
    }
}
